package com.java_enum;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class T {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //你这是什么意思？没什么意思，就是意思意思，小意思
        System.out.print("请输入一个字符串：");
        String word = input.next();
        String orignal = word;
        System.out.print("请输入要查找字符：");
        String keyword = input.next();
        /*int index = word.indexOf(keyword);
        int count = 0;
        while (index != -1){
            word = word.substring(index+keyword.length(),word.length());
            System.out.println(word);
            index = word.indexOf(keyword);
            count++;
        }
        System.out.println(index);*/
//正则表达式
        Pattern pattern = Pattern.compile(keyword);
        Matcher matcher = pattern.matcher(word);
        int count = 0;
        while(matcher.find()){
           count++;
        }
        System.out.println("“"+orignal+"”中出现" + count + "个" + keyword);
    }
}
